/*
 * FileName: MyProfiler.java
 * Author:   zzw
 * Date:     2018年10月31日
 * Description:
 */
package com.zzw.hotspot.attach;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 〈〉<br>
 * 〈〉
 *
 * @author zzw
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本]（可选）
 */
public class MyProfiler {
    public static ConcurrentHashMap<Class<?>, AtomicInteger> data = new ConcurrentHashMap<>();

    public static void fireAllocationEvent(Class<?> klass) {
        data.computeIfAbsent(klass, kls -> new AtomicInteger())
                .incrementAndGet();
    }

    public static void dump() {
        data.forEach((kls, counter) -> {
            System.err.printf("%s: %d\n", kls.getName(), counter.get());
        });
    }

    static {
        Runtime.getRuntime().addShutdownHook(new Thread(MyProfiler::dump));
    }
}
